var MainMenuLayer = cc.Layer.extend({
    ctor: function(){
        this._super();
    },
    init: function(){
        var bRet = false;
        if (this._super()) {
            var winSize = cc.Director.getInstance().getWinSize();
            //背景
            var sp = cc.Sprite.create(config.getBackground(), cc.rect(0, 0, config.width, config.height));
            sp.setAnchorPoint(cc.p(0, 0));
            this.addChild(sp, 0, 1);
            
            //logo
            var logo = cc.Sprite.create(s_logo);
            logo.setPosition(winSize.width / 2, winSize.height / 2 + 80);
            this.addChild(logo, 10, 1);
            
            //鸟
            var num = config.birdType;
            var bird = cc.Sprite.create(s_bird(num));
            bird.setPosition(cc.p(winSize.width / 2, winSize.height / 2 + 20));
            this.addChild(bird, 10, 1);
            bird.runAction(Animate.birdFly(num));
            bird.runAction(Animate.birdJump());
            
            //开始按钮
            var startItem = cc.MenuItemImage.create(s_button_play, s_button_play, this.onReady, this);
            startItem.setAnchorPoint(cc.p(0.5, 0.5));
            
            var menu = cc.Menu.create(startItem);
            menu.setPosition(cc.PointZero());
            this.addChild(menu, 1);
            startItem.setPosition(cc.p(winSize.width / 2, 138));
            
            //地面
            //removeFromParent(true)
            this.addChild(Ground.create());
			
            bRet = true;
        }
        return bRet;
    },
    onReady: function(){
        cc.log("--- Get Ready ---");
		sound.playSwooshingSound();
        cc.Director.getInstance().replaceScene(cc.TransitionFade.create(1.2, StartLayer.scene()));
    }
});

MainMenuLayer.create = function(){
    var sl = new MainMenuLayer();
    if (sl && sl.init()) {
        return sl;
    }
    return null;
}

MainMenuLayer.scene = function(){
    var scene = cc.Scene.create();
    var layer = MainMenuLayer.create();
    scene.addChild(layer);
    return scene;
}
